﻿using Castle.MicroKernel.Registration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wolfy.NetDisk.Infrastructure
{
    public class WindsorRegister
    {
        /// <summary>
        /// 注册单例
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="implementationType"></param>
        public static void RegisterSingleton(Type interfaceType, Type implementationType)
        {
            IoC.Container.Register(Component.For(interfaceType).ImplementedBy(implementationType).LifeStyle.Singleton);
        }
        /// <summary>
        /// 每次请求一次实例
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="implementationType"></param>
        public static void Register(Type interfaceType, Type implementationType)
        {
            IoC.Container.Register(Component.For(interfaceType).ImplementedBy(implementationType).LifeStyle.PerWebRequest);
        }
        public static void RegisterAllFromAssemblies(string a)
        {
            IoC.Container.Register(Classes.FromAssemblyNamed(a).Pick().WithService.DefaultInterfaces().LifestylePerWebRequest());
        }
    }
}
